package com.test.controller;

import com.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/user")

public class UserController {

	@Autowired
	UserService userService;

	@RequestMapping(value = "/all")
	@ResponseBody
	//读取所有用户
	public String getAllUsers() {
		return userService.getAllUsers();
	}

	@RequestMapping(value = "/reg")
	//读取所有用户
	public String reg() {
		return "reg";
	}
	
	@RequestMapping(value = "/doReg")
	@ResponseBody
	//读取所有用户
	public String doReg(@RequestParam("user") String username, @RequestParam("pwd") String pwd) {
		//1, 查询表里面有没有，有则返回已经有，如果没有，落表返回注册成功；
		if(userService.register(username, pwd)){
			return "注册成功";
		} else {
			return "注册失败";
		}
	}
}
